#!/bin/sh

CWD=$(pwd)

source /etc/make.conf

OVERLAY_FIXES=${CWD}
rm -fr ${CWD}/.diffs

#find ${PORTDIR_OVERLAY} -mindepth 2 -maxdepth 2 -type d -printf '%P\n' | while read E ; do
#    echo ${E}
#    mkdir -p ${CWD}/.diffs/${E}
#    diff -Nur ${PORTDIR}/${E} ${PORTDIR_OVERLAY}/${E} > ${CWD}/.diffs/${E}/all.diff
#done

find ${OVERLAY_FIXES} -name '*.ebuild' -printf '%P\n' | while read E ; do
    if [ -f ${PORTDIR}/${E} ] ; then
        echo ${E}
	D=$(dirname ${E})
	N=$(basename ${E})
	mkdir -p ${CWD}/.diffs/${D}
	pushd ${CWD}/.diffs &> /dev/null

	cp -f ${PORTDIR}/${E} ${E}-orig
	cp -f ${OVERLAY_FIXES}/${E} ${E}

	diff -u ${E}-orig ${E} > ${E}.diff
	rm -f ${E}-orig ${E}
	popd &> /dev/null
    fi
done

pushd ${CWD}/.diffs &> /dev/null
tar -cvf ${CWD}/portage.diffs.tar *
popd &> /dev/null
rm -fr ${CWD}/.diffs
